package com.witframework.web.tag.timer;

import java.util.Hashtable;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.BodyContent;
import javax.servlet.jsp.tagext.BodyTagSupport;

public class ClearTimerTag extends BodyTagSupport
{
  PageContext pageContext;
  private static final String DEFAULT_ID = "dflttmrdcj2008";
  private static final String TIMERTAG = "trmtgcj2008";
  private String id = null;
  private String scope = "application";
  private boolean cond = true;
  private String sBody = null;

  public void setId(String paramString)
  {
    this.id = paramString;
  }

  public String getId()
  {
    return this.id;
  }

  public void setScope(String paramString)
  {
    this.scope = paramString;
  }

  public String getScope()
  {
    return this.scope;
  }

  public void setCond(boolean paramBoolean)
  {
    this.cond = paramBoolean;
  }

  public boolean getCond()
  {
    return this.cond;
  }

  public void setPageContext(PageContext paramPageContext)
  {
    this.pageContext = paramPageContext;
  }

  public PageContext getPageContext()
  {
    return this.pageContext;
  }

  public int doAfterBody()
    throws JspException
  {
    BodyContent localBodyContent = getBodyContent();
    if (localBodyContent != null)
    {
      this.sBody = localBodyContent.getString();
      localBodyContent.clearBody();
    }
    if (this.sBody == null)
      this.sBody = "";
    return 0;
  }

  public int doEndTag()
    throws JspException
  {
    Hashtable localHashtable = getCodeHash();
    if (this.cond)
      synchronized (localHashtable)
      {
        if (this.id != null)
          localHashtable.remove(this.id);
        else
          localHashtable.clear();
      }
    dropData();
    return 6;
  }

  public void release()
  {
    dropData();
  }

  private void dropData()
  {
    this.id = null;
    this.scope = "application";
    this.cond = true;
    this.sBody = null;
  }

  private Hashtable getCodeHash()
  {
    Hashtable localHashtable = null;
    if ("application".equalsIgnoreCase(this.scope))
    {
      localHashtable = (Hashtable)this.pageContext.getAttribute("trmtgcj2008", 4);
      if (localHashtable == null)
      {
        localHashtable = new Hashtable();
        this.pageContext.setAttribute("trmtgcj2008", localHashtable, 4);
      }
    }
    else
    {
      localHashtable = (Hashtable)this.pageContext.getAttribute("trmtgcj2008", 3);
      if (localHashtable == null)
      {
        localHashtable = new Hashtable();
        this.pageContext.setAttribute("trmtgcj2008", localHashtable, 3);
      }
    }
    return localHashtable;
  }
}